home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / WIN_PRO / WTEK0593.ZIP;1 / SWITCH.ZIP / TEXTWIN.H < prev   
Encoding:
C/C++ Source or Header  |  1993-04-08  |  6.7 KB  |  167 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  TEXTWIN.H                                                             */
  4. /*                                                                        */
  5. /*  Header file for Dispatcher, WinData, and TextWindow                   */
  6. /*                                                                        */
  7. /*------------------------------------------------------------------------*/
  8.  
  9. #if !defined( TEXTWIN_H )
  10. #define TEXTWIN_H
  11.  
  12. #include <windows.h>
  13. #include <limits.h>
  14. #include <string.h>
  15. #include <vectimp.h>
  16. #include <stdtempl.h>
  17.  
  18. /*------------------------------------------------------------------------*/
  19. /*                                                                        */
  20. /*  class Dispatcher                                                      */
  21. /*                                                                        */
  22. /*  Registers callback function to handle dispatching to                  */
  23. /*  derived classes.                                                      */
  24. /*                                                                        */
  25. /*------------------------------------------------------------------------*/
  26.  
  27. class Dispatcher
  28. {
  29. protected:
  30.     Dispatcher() { Window = this; }
  31.     static LONG FAR PASCAL _export Callback( HWND, UINT, UINT, LONG );
  32.     virtual int Dispatch( UINT, UINT, LONG, LONG& ) = 0;
  33. private:
  34.     static Dispatcher *Window;
  35. };
  36.  
  37. /*------------------------------------------------------------------------*/
  38. /*                                                                        */
  39. /*  enum FuncType                                                         */
  40. /*  template struct DispatchRecord                                        */
  41. /*                                                                        */
  42. /*  Used to implement function dispatch database.                         */
  43. /*                                                                        */
  44. /*------------------------------------------------------------------------*/
  45.  
  46. enum FuncType
  47. {
  48.     VoidType,
  49.     UUType,
  50.     UType
  51. };
  52.  
  53. template <class T> struct DispatchRecord
  54. {
  55.     typedef long (T::*VoidFunc)();
  56.     typedef long (T::*UUFunc)( unsigned, unsigned );
  57.     typedef long (T::*UFunc)( unsigned );
  58.     DispatchRecord() {};
  59.     DispatchRecord( UINT m, FuncType t, VoidFunc p )
  60.         { Msg = m; Type = t; Proc = p; }
  61.     int operator == ( const DispatchRecord<T>& m )
  62.         { return Msg == m.Msg; }
  63.     int operator < ( const DispatchRecord<T>& m )
  64.         { return Msg < m.Msg; }
  65.     UINT Msg;
  66.     FuncType Type;
  67.     VoidFunc Proc;
  68. };
  69.  
  70. /*------------------------------------------------------------------------*/
  71. /*                                                                        */
  72. /*  template <class T> void RegisterProc()                                */
  73. /*                                                                        */
  74. /*  Function templates to handle typesafe member                          */
  75. /*  function registration.                                                */
  76. /*                                                                        */
  77. /*------------------------------------------------------------------------*/
  78.  
  79. template <class T> inline void RegisterProc( int msg, long (T::*Proc)() )
  80. {
  81.     T::Register( msg, VoidType, (DispatchRecord<T>::VoidFunc)Proc );
  82. }
  83.  
  84. template <class T> 
  85. inline void RegisterProc( int msg, long (T::*Proc)( unsigned, unsigned ) )
  86. {
  87.     T::Register( msg, UUType, (DispatchRecord<T>::VoidFunc)Proc );
  88. }
  89.  
  90. template <class T> 
  91. inline void RegisterProc( int msg, long (T::*Proc)( unsigned ) )
  92. {
  93.     T::Register( msg, UType, (DispatchRecord<T>::VoidFunc)Proc );
  94. }
  95.  
  96. /*------------------------------------------------------------------------*/
  97. /*                                                                        */
  98. /*  class WinData                                                         */
  99. /*                                                                        */
  100. /*  Stores and maintains basic data about the window.                     */
  101. /*                                                                        */
  102. /*------------------------------------------------------------------------*/
  103.  
  104. class WinData : public virtual Dispatcher
  105. {
  106. public:
  107.     static void Register( UINT m, FuncType t,
  108.                           DispatchRecord<WinData>::VoidFunc p )
  109.         { Map.add( DispatchRecord<WinData>(m,t,p) ); }
  110. protected:
  111.     WinData() {RegisterProc( WM_SIZE, &WinData::OnSize ); }
  112.     long OnSize( unsigned, unsigned );
  113.     virtual void Resized() {};
  114.     unsigned GetWinHeight() const { return WinHeight; }
  115.     unsigned GetWinWidth() const { return WinWidth; }
  116.     unsigned GetCharHeight() const { return CharHeight; }
  117.     unsigned GetCharWidth() const { return CharWidth; }
  118.     HWND GetHandle() const { return Handle; }
  119.     void SetHandle( HWND );
  120.     virtual int Dispatch( UINT, UINT, LONG, LONG& );
  121. private:
  122.     unsigned WinHeight;
  123.     unsigned WinWidth;
  124.     unsigned CharHeight;
  125.     unsigned CharWidth;
  126.     HWND Handle;
  127.     static BI_SVectorImp<DispatchRecord<WinData> > Map;
  128. };
  129.  
  130. /*------------------------------------------------------------------------*/
  131. /*                                                                        */
  132. /*  class TextWindow                                                      */
  133. /*                                                                        */
  134. /*  Displays static text in a non-scrollable window.                      */
  135. /*                                                                        */
  136. /*------------------------------------------------------------------------*/
  137.  
  138. class TextWindow : public virtual WinData, public virtual Dispatcher
  139. {
  140. public:
  141.     TextWindow()
  142.         {
  143.         RegisterProc( WM_PAINT, &TextWindow::OnPaint );
  144.         RegisterProc( WM_DESTROY, &TextWindow::OnDestroy );
  145.         }
  146.     void Create( HWND, int, DWORD = 0 );
  147.     static void Register( UINT m, FuncType t, DispatchRecord<TextWindow>::VoidFunc p )
  148.         { Map.add( DispatchRecord<TextWindow>( m, t, p ) ); }
  149. protected:
  150.     long OnPaint();
  151.     long OnDestroy();
  152.     virtual int GetXPos() const { return 0; }
  153.     virtual int GetYPos() const { return 0; }
  154.     virtual int Dispatch( UINT, UINT, LONG, LONG& );
  155.     static int Lines();
  156.     static int Width() { return MaxWidth; }
  157. private:
  158.     int RegisterClass( HWND );
  159.     int CreateWindow( HWND, DWORD );
  160.     static BI_SVectorImp<DispatchRecord<TextWindow> > Map;
  161.     static char *Text[];
  162.     static int MaxWidth;
  163.     static int FindWidest();
  164. };
  165.  
  166. #endif  // TEXTWIN_H
  167.